<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI 排序（Sortable） - 连接列表</title>
 <link rel="stylesheet" href="jquery-ui-1.10.4.custom/css/base/jquery-ui-1.10.4.custom.css">
  <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
 <!--
 <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
 --> 
  <script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.js"></script>
  <link rel="stylesheet" href="jqueryui/style.css">
  <style>
  #sortable1, #sortable2 ,xx{ list-style-type: none; margin: 0; padding: 0 0 2.5em; float: left; margin-right: 10px; }
  #sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
  </style>
  <script>
  $(function() {
  	var str = '<ul id="sortable1" class="connectedSortable">'
 			 +'<li id="zz" class="ui-state-default" ><div onclick="vv()">vvvvvv</div></li>'
 
				+'</ul>';
//	$("body").prepend(str);
  	
//	 $( "#zz" ).draggable({
//    drag: function(e,ui){
////    	console.log( ui.draggable.text())
//	      	console.log(222 )
//	      	  $( "#cc" ).position({
//	        of: $( "#zz" ),
//	        my: "right top",
//	        at: "right top",
//	        collision: "none none"
//	      });
//    }
//  });
//	console.log("xxxxxx")
    $( "#sortable1, #sortable2" ).sortable({
     /* drag: function(){
      	
      	console.log(111 )
      	  $( "#xx div:first" ).position({
        of: $( "#zz" ),
        my: "right top",
        at: "right top",
        collision: "none none"
      });
      },
      sort : function(){ 
      	console.log("sort")
//    	console.log($(this).text())
      },*/
      connectWith: ".connectedSortable"
    })
    .droppable({
    	   drop: function( event, ui ) {
    	   	
    	   	
        $( this ).find("li").width(100);
		  console.log(ui)
		  console.log(ui.draggable.text())
		  ui.draggable.width(100);
		  ui.draggable.css("background-color","red");
//		  ui.draggable.remove();
		  console.log(ui.draggable.width())
//		  $()
        $( "<li></li>" ).text( ui.draggable.text() ).appendTo( this );
      
    	   ff (); 
    	   }
    })
    .disableSelection();
  });
  
  function ff(){
  	
  	 var w = $("#sortable1").width();
  	var n = $("#sortable1 li").length;
  	console.log(n)
  	$("#sortable1 li").width(w/n)
  	$("#sortable1 li").each(function(){
  		console.log($(this).width())
  	})
  	
  	
  	
  }
  function vv(){
  	console.log("vvvvvvvvvvv")
  }
  </script>
</head>
<body>
 
<ul id="sortable1" class="connectedSortable">
  <li id="zz" class="ui-state-default" ><div onclick="vv()">vvvvvv</div></li>
  <li class="ui-state-default">Item 2</li>
  <li class="ui-state-default">Item 3</li>
  <li class="ui-state-default">Item 4</li>
  <li class="ui-state-default">Item 5</li>
</ul>
<ul id="sortable2" class="connectedSortable">
  <li class="ui-state-highlight">Item 1</li>
  <li class="ui-state-highlight">Item 2</li>
  <li class="ui-state-highlight">Item 3</li>
  <li class="ui-state-highlight">Item 4</li>
  <li class="ui-state-highlight">Item 5</li>
</ul>

   <div id="xx" >
  <div id="cc" style="width: 30px; height: 20px;background-color: red;"> 1</div>
  <div style="width: 10px; height: 20px;"> 2</div>
  <div style="width: 10px; height: 20px;"> 3</div>
  <div style="width: 10px; height: 20px;"> 4</div>
  <div style="width: 10px; height: 20px;"> 5</div>
</div>
 
</body>
</html>